package com.bdsy.business.controller;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.bdsy.business.model.IntroGood;
import com.bdsy.business.model.ShopType;
import com.bdsy.business.service.IntroGoodService;
import com.bdsy.common.annotation.Json;
import com.bdsy.common.utils.Result;
import com.bdsy.system.annotation.SysLog;

/**
 * 品述
 * @author MING
 * @date 2018年3月15日 上午10:40:20
 */
@Controller
@RequestMapping(value = {"${web.adminPath}", "${web.appPath}"})
public class IntroGoodController {

	@Autowired
	IntroGoodService introGoodService;
	
	/**
	 * 查询品述信息
	 */
	@Json
	@RequestMapping(value = "introGoodList")
	public Object introGoodList() {
		Map<String, Object> map = new LinkedHashMap<>();
		@SuppressWarnings("rawtypes")
		List<Map> introGoodList = introGoodService.selectIntroGoodList();
		map.put("code", 200);
		map.put("msg", "success");
		map.put("data", introGoodList);
		return map;
	}
	
	
	
	//后台----------------------------
	@RequestMapping(value = "introGood")
	public String introGood() {
		return "admin/business/introGood";
	}
	
	@SysLog("添加品述信息 -- 缺少图片 ")
	@Json
	@RequestMapping(value = "insertIntroGood")
	public Object insertIntroGood(MultipartFile file,IntroGood introGood) {
		boolean result = introGoodService.insert(file,introGood);
		if (result) {
			return Result.ok("添加成功");
		} else {
			return Result.error("添加失败");
		}
	}
	
	@SysLog("查询品述信息 ")
	@Json
	@RequestMapping(value = "introGoodLists")
	public Object introGoodLists() {
		@SuppressWarnings("rawtypes")
		List<Map> introGoodList = introGoodService.selectIntroGoodList();
		return introGoodList;
	}
	
	@SysLog("根据ID查询品述信息 ")
	@Json
	@RequestMapping(value = "introGoodById")
	public Object introGoodById(int id) {
		List<IntroGood> introGood = introGoodService.introGoodById(id);
		return introGood;
	}
	
	@SysLog("修改品述信息 ")
	@Json
	@RequestMapping(value = "updateIntroGoodById")
	public Object updateIntroGoodById(IntroGood introGood) {
		boolean result = introGoodService.update(introGood);
		if (result) {						 
			return Result.ok("修改成功");
		} else {
			return Result.error("修改失败");
		}
	}
	
	@SysLog("删除品述信息 ")
	@Json
	@RequestMapping(value = "deleteIntroGoodById")
	public Object deleteIntroGoodById(String pIds) {
		List<String> list = JSON.parseArray(pIds, String.class);
		boolean result = introGoodService.delete(list);
		if (result) {						 
			return Result.ok("删除成功");
		} else {
			return Result.error("删除失败");
		}
	}
	
}
